package newbie;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseServlet extends HttpServlet{

	//http://www.java2s.com/Code/Java/Servlets/ServletMultipleInclude.htm
	public void  init(ServletConfig conf) throws ServletException{
		super.init(conf);
	}

	public void  doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");

		PrintWriter p = response.getWriter();

		p.println("<html>");
		p.println("<title>");
		p.println("Base servlet");
		p.println("</title>");
		p.println("<body>");
		p.println("<p>From base servlet</p>");

		RequestDispatcher dispatcher = request.getRequestDispatcher("/IncludeServlet");

		if(dispatcher != null) {
			//dispatcher.forward(request, response);
			dispatcher.include(request, response);
		}

		p.println("</body>");
		p.println("</html>");
	}



}
